<?php
  
  
  require("abifunktsioonid.php");
   $otsisona="";
  session_start();
 if($_SESSION["group_type"]!="2"){
 header("Location: login.php");
 exit();
 }
 
 if(isSet($_REQUEST["lahku"])){
 unset($_SESSION["username"]);
  header("Location: login.php");
 exit();
 }
  
  
  if(isSet($_REQUEST["lepingulisamine"])){
    lisaLeping($_REQUEST["assignment"], $_REQUEST["customer_id"], $_REQUEST["location"]);
    header("Location: manager.php");
    exit();
  }
  if(isSet($_REQUEST["kustutusid"])){
     kustutaLeping($_REQUEST["kustutusid"]);
  }
  if(isSet($_REQUEST["muutmine"])){
     muudaLeping($_REQUEST["muudetudid"], $_REQUEST["assignment"], $_REQUEST["location"], $_REQUEST["complete"]);
  }
  
 

  if(isSet($_REQUEST["otsisona"])){
     $otsisona=$_REQUEST["otsisona"];
  }
  $tootajad=kysiKliendiAndmed($otsisona);
 
 
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
 <meta charset="UTF-8"/>
<link rel="stylesheet" type="text/css" href="kujundus.css">
 <title>Bon Services OY</title>

 </head>
 <body>
<div id="main">
 <img id="header" src="bso.png" alt="logo" href="login.php"/>
 </div>
 <div id="main2">

 <div id="main3">
 
 
 
  
	 <form action="manager.php">
     <p id="located">Kustuta ja muuda lepinguid</p>
     <table id="located">
       <tr>
         <th>Haldus</th>
         <th>Leping</th>
         <th>Asukoht</th>
		 <th>Valmidus</th>
       </tr>
       <?php foreach($tootajad as $tooline): ?>
         <tr>
          <?php if(isSet($_REQUEST["muutmisid"]) &&
                            intval($_REQUEST["muutmisid"])==$tooline->id): ?>
           <td>
             <input type="submit" name="muutmine" value="Muuda" />
             <input type="submit" name="katkestus" value="Katkesta" />
             <input type="hidden" name="muudetudid" value="<?php echo $tooline->id ?>" />
           </td>
           <td><input type="text" name="assignment" value="<?php echo $tooline->assignment ?>" /></td>
           <td><input type="text" name="location" value="<?php echo $tooline->location ?>" /></td>
		   <td><input type="text" name="complete" value="<?php echo $tooline->complete ?>" /></td>
          <?php else: ?>          
           <td><a id="lahku" href="manager.php?kustutusid=<?php echo $tooline->id ?>"
                  onclick="return confirm('Kas ikka soovid kustutada?')">x</a>
               <a href="manager.php?muutmisid=<?php echo $tooline->id ?>">m</a>
           </td>
          
           <td id="rida"><?php echo $tooline->assignment ?></td>
           <td id="rida"><?php echo $tooline->location ?></td>
		   <td id="rida"><?php if($tooline->complete=="0"){echo "Ei ole täidetud";} elseif($tooline->complete=="1"){echo "Täidetud";}?></td>
          <?php endif ?>
         </tr>
       <?php endforeach; ?>
     </table>
   </form>
	 
	 <div style="margin-top:100px;" id="kasutaja">
	 <a href="login.php" id="tagasi">Tagasi</a>
	  <p id="kasutajad"><?php echo $_SESSION["realname"]; ?>
 <a href="?lahku" id="lahku">lahku</a></p>
 </div>
	 </div>
	 
	 </div>
  </body>
</html>